<?php

namespace app\admin\model\shop\user;

use app\admin\model\distribution\Grade;
use think\Model;

/**
 * User
 */
class User extends Model
{
    // 表名
    protected $name = 'shop_user';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    public function getAvatarAttr($value): string
    {
        return full_url($value, false, config('buildadmin.default_avatar'));
    }

    public function setAvatarAttr($value): string
    {
        return $value == full_url('', false, config('buildadmin.default_avatar')) ? '' : $value;
    }

    public function getMoneyAttr($value): string
    {
        return bcdiv($value, 100, 2);
    }

    public function setMoneyAttr($value): string
    {
        return bcmul($value, 100, 2);
    }

    public function getScoreAttr($value): string
    {
        return bcdiv($value, 100, 2);
    }

    public function setScoreAttr($value): string
    {
        return bcmul($value, 100, 2);
    }

    public function distributiongrade(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(Grade::class, 'grade_id', 'id');
    }
}